<?php
	session_start();
	
	$host="localhost";
	$username="root";
	$password="";
	$database="cs4400_group17";

	mysql_connect($host,$username,$password);
	@mysql_select_db($database) or die( "Unable to select database");
	
	$username = $_SESSION['userName'];
	$useremail = $_SESSION['userEmail'];
	
	$corkboardOwnEmail = $_GET['OwnerEmail'];
	$corkboardTitle = $_GET['corkTitle'];

	echo "Content-Type: text/html\n\n";
	
	echo $corkboardOwnEmail;
	
	$sql = "SELECT * FROM userwatches WHERE Title = '$corkboardTitle' AND OwnerEmail = '$corkboardOwnEmail' AND Email = '$useremail'";
	$result = mysql_query($sql);
	$rows = mysql_fetch_array($result);
	
	if($rows[0] == $useremail){
		$sql = "DELETE FROM userwatches WHERE Title = '$corkboardTitle' AND OwnerEmail = '$corkboardOwnEmail' AND Email = '$useremail'";
		$result = mysql_query($sql);
	}
	else{
		$sql = "INSERT INTO userwatches VALUES('$useremail','$corkboardTitle','$corkboardOwnEmail')";
		$result = mysql_query($sql);
	
	}
	
	header("location:home.php");
	
	
?>
